/*:
* @plugindesc 枫之舞功能 - 行走图近大远小
* @author 老饕
* @version 1.0.0
* @date 3/21/2020
* 
* @help
* 行走图近大远小功能
* 
* 地图标签
* <Scale: upperScale, lowerScale>
* 指定角色在地图最上方和地图最下方时的缩放比例。
*/
let SWDA_CharacterPerspective = {};



// 补充尺寸
SWDA_CharacterPerspective.spriteCharacterInitMembers = Sprite_Character.prototype.initMembers;
Sprite_Character.prototype.initMembers = function () {
    SWDA_CharacterPerspective.spriteCharacterInitMembers.call(this);
    this._zoomRate = 1;
};

// 补充更新尺寸
SWDA_CharacterPerspective.spriteCharacterUpdate = Sprite_Character.prototype.update;
Sprite_Character.prototype.update = function () {
    this.updateZoomRate();
    SWDA_CharacterPerspective.spriteCharacterUpdate.call(this);

};
// 更新放大率
Sprite_Character.prototype.updateZoomRate = function () {

    if ($dataMap.meta && $dataMap.meta["Scale"]) {
        const data = $dataMap.meta["Scale"].split(",");
        if (data.length >= 2) {
            const upperScale = Number(data[0]) || 1;
            const lowerScale = Number(data[1]) || 1;
            this._zoomRate = (this._character._realY / $dataMap.height) * (lowerScale - upperScale) + upperScale;
        }

    }
};

// 更新行走图、气泡尺寸
SWDA_CharacterPerspective.spriteCharacterUpdatePosition = Sprite_Character.prototype.updatePosition;
Sprite_Character.prototype.updatePosition = function () {
    SWDA_CharacterPerspective.spriteCharacterUpdatePosition.call(this);
    this.scale.x = this._zoomRate;
    this.scale.y = this._zoomRate;
};


SWDA_CharacterPerspective.spriteCharacterUpdateBalloon = Sprite_Character.prototype.updateBalloon;
Sprite_Character.prototype.updateBalloon = function () {
    SWDA_CharacterPerspective.spriteCharacterUpdateBalloon.call(this);
    if (this._balloonSprite) {
        this._balloonSprite.scale.x = this._zoomRate;
        this._balloonSprite.scale.y = this._zoomRate;
        this._balloonSprite.y = this.y - (this.height - 20) * this._zoomRate;
    }
};